import java.util.Calendar;

import junit.framework.TestCase;

public class TestAppointment extends TestCase {
	Calendar earlier, now, later, latest;
	
	protected void setUp() throws Exception {
		earlier = Calendar.getInstance();
		now = Calendar.getInstance();
		later = Calendar.getInstance();
		latest = Calendar.getInstance();
		later.add(Calendar.HOUR_OF_DAY, 1);
		latest.add(Calendar.HOUR_OF_DAY, 2);
		earlier.add(Calendar.HOUR_OF_DAY, -1);
	}
	
	public void testAdjacentAppointmentsDoNotOverlap(){
		Appointment firstAppointment = new Appointment(now, later,"first");
		Appointment secondAppointment = new Appointment(later, latest,"second");
		assertFalse(firstAppointment.overlaps(secondAppointment));
	}
	
	public void testSameAppointmentsOverlap(){
		Appointment Appointment = new Appointment(now, later,"me");
		Appointment sameAppointment = new Appointment(now, later,"myself");
		assertTrue(Appointment.overlaps(sameAppointment));
	}

	public void testDistinctAppointmentsDoNotOverlap(){
		Appointment Appointment = new Appointment(earlier, now,"first");
		Appointment laterAppointment = new Appointment(later, latest,"last");
		assertFalse(Appointment.overlaps(laterAppointment));
	}
	
	public void testPartialOverlappingAppointmentsOverlap(){
		Appointment Appointment = new Appointment(earlier, later,"first");
		Appointment laterAppointment = new Appointment(now, latest,"second");
		assertTrue(Appointment.overlaps(laterAppointment));
	}
	
	public void testAppointmentsWithSameStartButDifferentEndsOverlap(){
		Appointment Appointment = new Appointment(now, later,"one");
		Appointment concurrentAppointment = new Appointment(now, latest,"two");
		assertTrue(Appointment.overlaps(concurrentAppointment));
	}
	
	public void testWeirdCaseOfAppointmentsThatHaveNoDuration(){
		Appointment weirdAppointment = new Appointment(now, now,"one");
		Appointment otherWeirdAppointment = new Appointment(now, now,"two");
		assertFalse(weirdAppointment.overlaps(otherWeirdAppointment));
	}
	
	public void testAppointmentIsBusiness() throws Exception {
		Appointment businessAppointment = new Appointment(now,later,"foo",AppointmentType.BUSINESS);
		Appointment personalAppointment = new Appointment(now,later,"foo",AppointmentType.PERSONAL);
		assertTrue(businessAppointment.isBusiness());
		assertFalse(personalAppointment.isBusiness());
	}
	
	public void testAppointmentTypeReturnsCorrectImportance(){
		Appointment businessAppointment = new Appointment(now,later,"foo",AppointmentType.BUSINESS);
		Appointment personalAppointment = new Appointment(now,later,"foo",AppointmentType.PERSONAL);
		Appointment medicalAppointment = new Appointment(now,later,"foo",AppointmentType.MEDICAL);
		assertEquals(businessAppointment.returnImportance(businessAppointment),5);
		assertEquals(personalAppointment.returnImportance(personalAppointment),1);
		assertEquals(medicalAppointment.returnImportance(medicalAppointment),10);
	}
	
}